using System;
using System.Reflection;
using System.Collections;

using System.Xml.Serialization;

namespace G2007.CodeGen.Library.Data
{

	// this is the class that defines enumeration types - it is not an enumeration, don't get confused
	[Serializable]
	public class Enum
	{


		[XmlIgnore()]
		protected string[] names;

		public string[] Names { get { return names; } set { names=value; } }

		protected string name;
		public string Name { get { return name; } set { name=value; } }

		protected HeaderInfo hi;
		public HeaderInfo @HeaderInfo { get { return hi; } set { hi=value; } }


		protected string[] data;

		public Enum() {}

		public override string ToString()
		{
			string namesL=name + " :";

			foreach(string n in names) 
			{
				namesL+=n + " ";
			}
			return namesL;
		}



		public Enum(string name, HeaderInfo hi, string[] data) 
		{
			this.name=name;
			this.hi=hi;
			this.data=data;
		}

		public bool GenerateFields(out string error) 
		{
			error="";
			int x=0;
			foreach(string s in data) 
			{
				if(s.ToUpper().StartsWith("ENUM")) 
				{

					if(s.Split('\t')[1].Trim().Equals(name)) 
					{
						ArrayList vals=new ArrayList();
						int y=x+1;
						while(y<data.Length) 
						{
							if(data[y].ToUpper().Trim().Equals("END ENUM")) 
							{
								break;
							}

							if(data[y].Length>2) 
							{
								vals.Add(data[y].Trim());
							}

							y++;
						}
						this.names=(string[])vals.ToArray(typeof(string));
					}
				}
				x++;
			}
			return true;
		}
	}
}
